package Top200;

/**
 * @author zhangmin
 * @create 2022-02-24 14:15
 */
public class isNumber65 {
    int index=0;

    //判断是否时有符号的整数
    boolean isInt(String s){
        if (index==s.length()) return false;
        if (s.charAt(index)=='+'||s.charAt(index)=='-') index++;
        return isUnsignInt(s);
    }
    boolean isUnsignInt(String s){
        int start=index;
        while (index!=s.length()&&s.charAt(index)<='9'&&s.charAt(index)>='0'){
            index++;
        }
        return index>start;
    }
    public boolean isNumber(String s) {
        int n=s.length();
        //数值部分
        boolean number = isInt(s);
        if (index==s.length()) return number;
        //判断是否是小数
        if (s.charAt(index)=='.'){
            index++;
            //小数点后面应该为一个整数或者没有数字
            number=isUnsignInt(s)||number;
        }
        if (index==s.length()) return number;
        //判断是否是e或E
        if (s.charAt(index)=='e'||s.charAt(index)=='E'){
            index++;
            number=number&&isInt(s);
        }
        return index==s.length()&&number;
    }

    public static void main(String[] args) {
        String s="0.8";
        isNumber65 obj=new isNumber65();
        System.out.println(obj.isNumber(s));
    }
}
